<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="{__STATIC_PATH}layuiadmin/layui/css/layui.css" media="all">
    <link rel='stylesheet' href='{__STATIC_PATH}layuiadmin/style/admin.css' media='all'>
    <script src="{__STATIC_PATH}/layuiadmin/layui/layui.js"></script>
    <script>
        layui.config({
            base: '{__STATIC_PATH}layuiadmin/' //静态资源所在路径
        })
    </script>
    <style type="text/css">
        /*
         * 设置图片外层div的高度
         */
        .layui-table-cell{
            height: 100%;
            max-width: 100%;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <form onsubmit="return false;">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">渠道</label>
                    <div class="layui-input-inline">
                        <select name="channel_id" lay-verify="">
                            <option value="">--选择--</option>
                            {volist name="arr_channel_list" id="vo"}
                            <option value="{$vo.id}">{$vo.name}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">推广专员</label>
                    <div class="layui-input-inline">
                        <select name="tuiguang_admin_id" lay-verify="">
                            <option value="">--选择--</option>
                            {volist name="arr_tuiguangzhuanyuan_list" id="vo"}
                            <option value="{$vo.id}">{$vo.name}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">创业顾问</label>
                    <div class="layui-input-inline">
                        <select name="chuangye_admin_id" lay-verify="">
                            <option value="">--选择--</option>
                            {volist name="arr_chuangyeguwen_list" id="vo"}
                            <option value="{$vo.id}">{$vo.name}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
        </form>
        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
<!--                <button class="layui-btn layuiadmin-btn-list" data-type="add">添加</button>-->
            </div>
            <table id="table-list" lay-filter="lay-table-list"></table>
            <script type="text/html" id="table-content-list">
<!--                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>-->
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
            <script type="text/html" id="checkboxTpl">
                <!-- 这里的 checked 的状态只是演示 -->
                <input type="checkbox"  name="lock" value="{{d.id}}" title="锁定" lay-filter="adminLock" {{ d.is_lock == 2 ? 'checked' : '' }}>
            </script>
        </div>
    </div>
</div>
<script>
    layui.extend({
        index: 'lib/index' //主入口模块
    }).use(['index','table','layer'], function(){
        var table = layui.table
            ,form = layui.form
            ,$ = layui.$
            ,layer = layui.layer;
        var admin = layui.admin;
        var tableIns=table.render({
            elem: '#table-list' //指定原始表格元素选择器（推荐id选择器）
            ,url: '/admin/promotion/promotionRecordGetListData' //数据接口
            ,page: true //开启分页
            ,height: 'full-180'//高度最大适应
            ,limit:20
            ,limits:[20,50,100]
            ,cols: [[
                {type:'numbers',title:'编号'},
                {field:"id",title:"ID",},
                {field:"date",title:"日期",},
                {field:"channel_name",title:"渠道",},
                {field:"all_num",title:"总量",},
                {field:"valid_num",title:"有效量",},
                {field:"valid_per",title:"有效率",},
                {field:"tuiguang_admin_name",title:"推广专员",},
                {field:"chuangye_admin_name",title:"创业顾问",},
                {field:"create_time",title:"创建时间"},
                {field:"modify_time",title:"修改时间"},
                {title:"操作",minWidth:250,align:"center",fixed:"right",toolbar:"#table-content-list"}
            ]] //设置表头
            //,…… //更多参数参考右侧目录：基本参数选项
        });
        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('table-list', {
                where: field,
                page:{curr:1}
            });
        });
        active = {
            add: function(){
                layer.open({
                    type: 2
                    ,title: '添加'
                    ,content: '/admin/promotion/promotionRecordAdd'
                    ,maxmin: true
                    ,area: ['550px', '80%']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                        submit.click();
                    }
                });
            },
        };
        $('.layui-btn.layuiadmin-btn-list').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        //监听工具条
        table.on('tool(lay-table-list)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('此操作会删除当天该推广专员的所有数据，确定删除该数据？', function(index){
                    //obj.del();//删除对应行（tr）的DOM结构，并更新缓存
                    //向服务器发送删除请求
                    admin.req({
                        url: "/admin/promotion/promotionRecordDel?id="+obj.data.id
                        ,type: "POST"
                        ,datatype:'json'
                        ,success: function(res){
                            if (res.code == 0) {
                                layer.msg('删除成功',{time:500},function(){
                                    tableIns.reload('table-list'); //重载表格
                                    parent.layer.close(index); //再执行关闭
                                });
                            }
                            else {
                                layer.msg(res.msg);
                            }
                        }
                    });
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.open({
                    type: 2
                    ,title: '编辑'
                    ,content: "/admin/promotion/promotionRecordEdit?id="+ data.id
                    ,maxmin: true
                    ,area: ['550px', '80%']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var submit = layero.find('iframe').contents().find("#admin-edit-submit");
                        submit.click();
                    }
                });
            } else if(obj.event === 'bind-content'){
                window.location.href="/admin/aaa/ProductContentGetList?product_id="+ data.id;
            }
        });
    });
</script>
</body>
</html>